In [2]:
import sys,os
sys.path.append(os.path.abspath('../src/')) # para importar nbpil
try:
    sys.imagepath.append(os.path.abspath('../data/')) # caminho para imagens
except:
    sys.imagepath = [os.path.abspath('../data/')]
import numpy as np

import nbpil
#import PIL
from PIL import Image
#from nbpil import nbread
print(sys.imagepath)


[NbConvertApp] WARNING | pattern 'nbpil.ipynb' matched no files
This application is used to convert notebook files (*.ipynb) to various other
formats.

WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.

Options
-------

Arguments that take values are actually convenience aliases to full
Configurables, whose aliases are listed on the help line. For more information
on full configurables, see '--help-all'.

--debug
    set log level to logging.DEBUG (maximize logging output)
--generate-config
    generate default config file
-y
    Answer yes to any questions instead of prompting.
--execute
    Execute the notebook prior to export.
--allow-errors
    Continue notebook execution even if one of the cells throws an error and include the error message in the cell output (the default behaviour is to abort conversion). This flag is only relevant if '--execute' was specified, too.
--stdin
    read a single notebook file from stdin. Write the resulting notebook with default basename 'notebook.*'
--stdout
    Write notebook output to stdout instead of files.
--inplace
    Run nbconvert in place, overwriting the existing notebook (only 
    relevant when converting to notebook format)
--log-level=<Enum> (Application.log_level)
    Default: 30
    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
    Set the log level by value or name.
--config=<Unicode> (JupyterApp.config_file)
    Default: ''
    Full path of a config file.
--to=<Unicode> (NbConvertApp.export_format)
    Default: 'html'
    The export format to be used, either one of the built-in formats, or a
    dotted object name that represents the import path for an `Exporter` class
--template=<Unicode> (TemplateExporter.template_file)
    Default: ''
    Name of the template file to use
--writer=<DottedObjectName> (NbConvertApp.writer_class)
    Default: 'FilesWriter'
    Writer class used to write the  results of the conversion
--post=<DottedOrNone> (NbConvertApp.postprocessor_class)
    Default: ''
    PostProcessor class used to write the results of the conversion
--output=<Unicode> (NbConvertApp.output_base)
    Default: ''
    overwrite base name use for output files. can only be used when converting
    one notebook at a time.
--output-dir=<Unicode> (FilesWriter.build_directory)
    Default: ''
    Directory to write output to.  Leave blank to output to the current
    directory
--reveal-prefix=<Unicode> (SlidesExporter.reveal_url_prefix)
    Default: ''
    The URL prefix for reveal.js. This can be a a relative URL for a local copy
    of reveal.js, or point to a CDN.
    For speaker notes to work, a local reveal.js prefix must be used.
--nbformat=<Enum> (NotebookExporter.nbformat_version)
    Default: 4
    Choices: [1, 2, 3, 4]
    The nbformat version to write. Use this to downgrade notebooks.

To see all available configurables, use `--help-all`

Examples
--------

    The simplest way to use nbconvert is
    
    > jupyter nbconvert mynotebook.ipynb
    
    which will convert mynotebook.ipynb to the default format (probably HTML).
    
    You can specify the export format with `--to`.
    Options include ['custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'rst', 'script', 'slides', 'html_embed', 'html_toc', 'html_with_lenvs', 'html_with_toclenvs', 'latex_with_lenvs', 'selectLanguage']
    
    > jupyter nbconvert --to latex mynotebook.ipynb
    
    Both HTML and LaTeX support multiple output templates. LaTeX includes
    'base', 'article' and 'report'.  HTML includes 'basic' and 'full'. You
    can specify the flavor of the format used.
    
    > jupyter nbconvert --to html --template basic mynotebook.ipynb
    
    You can also pipe the output to stdout, rather than a file
    
    > jupyter nbconvert mynotebook.ipynb --stdout
    
    PDF is generated via latex
    
    > jupyter nbconvert mynotebook.ipynb --to pdf
    
    You can get (and serve) a Reveal.js-powered slideshow
    
    > jupyter nbconvert myslides.ipynb --to slides --post serve
    
    Multiple notebooks can be given at the command line in a couple of 
    different ways:
    
    > jupyter nbconvert notebook*.ipynb
    > jupyter nbconvert notebook1.ipynb notebook2.ipynb
    
    or you can specify the notebooks list in a config file, containing::
    
        c.NbConvertApp.notebooks = ["my_notebook.ipynb"]
    
    > jupyter nbconvert --config mycfg.py

['/Users/robertoalotufo/mylocalprojects/mylocalprojects/ia898/data']

In [15]:
print dir(nbpil)


['IPython', 'Image', 'PIL2array', 'StringIO', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '__version_string__', 'array2PIL', 'array2pil', 'findImageFile', 'listImageFiles', 'nbimages', 'nbread', 'nbreadgray', 'nbshow', 'nbwrite', 'np', 'pil2array']

In [16]:
img = nbpil.findImageFile('mandril_color.tif')
p = Image.open(img)
print p.mode
print p


RGB
<PIL.TiffImagePlugin.TiffImageFile image mode=RGB size=512x512 at 0x7F590E5F0A50>

In [17]:
#f = nbpil.nbread('/opt/projects/ia898/data/boat.png')
f = nbpil.nbread('/opt/projects/ia898/data/cameraman.tif')
print f.shape,f.dtype


(256, 256) uint8

In [18]:
g = 255 - f
!ls ../data/
nbpil.nbwrite('../data/cameraman_neg.png',g)
g1 = nbpil.nbread('cameraman_neg.png')


boat.png  camaraman_neg.png  cameraman_neg.png
boat.tif  cameraman.tif      mandril_color.tif

In [19]:
nbpil.nbshow(f,'Original')
nbpil.nbshow(g1,'negada escrita e leitura')
nbpil.nbshow(f,'Negada com formato de 50 pixels de largura',width=50)


Original
negada escrita e leitura
Negada com formato de 50 pixels de largura

Mostrando uma imagem binária, tipo bool


In [20]:
x,y = np.indices((155,240))
b = ((x/5+y/5)%2).astype(bool)
nbpil.nbshow(b,width=400)



In [ ]:


In [21]:
print sys.imagepath
dir(sys.imagepath)
nbpil.nbimages()


['/opt/projects/ia898/data', '/opt/projects/ia898/data', '/opt/projects/ia898/data']
Out[21]:
['boat.png',
 'boat.tif',
 'camaraman_neg.png',
 'cameraman.tif',
 'cameraman_neg.png',
 'mandril_color.tif']

In [13]:
for fname in nbpil.nbimages():
    f = nbpil.nbread(fname)
    nbpil.nbshow(f,fname)


boat.png
boat.tif
camaraman_neg.png
cameraman.tif
cameraman_neg.png
mandril_color.tif

In [ ]:


In [ ]: